﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using DAL;
using DTO;

namespace BLL
{
    public class QualificationBLL
    {
        static int id = 0;
        HospitalDataContext DB = new HospitalDataContext();
        public List<Qualification> Select(string staffID)
        {
            return DB.Qualifications.Where(q => q.StaffID == staffID).ToList();
        }
        public string Insert(QualificationDTO qualificationDTO)
        {
            try
            {
                Qualification qua = new Qualification();
                qua.QualificationID= (id++).ToString();
                qua.StaffID = qualificationDTO.Staffid;
                qua.Type = qualificationDTO.Type;
                qua.Date = qualificationDTO.Date;
                qua.Institution = qualificationDTO.Institution;

                DB.Qualifications.InsertOnSubmit(qua);
                DB.SubmitChanges();
                return "success";
            }
            catch (Exception ex)
            {

                return ex.Message;
            }
            finally
            {
                id = new Random().Next(100);
            }
        }
        public string Update(QualificationDTO qualificationDTO)
        {
            try
            {
                Qualification qua = DB.Qualifications.Where(q => q.QualificationID==qualificationDTO.QualificationID).FirstOrDefault();
                qua.Type = qualificationDTO.Type;
                qua.Date = qualificationDTO.Date;
                qua.Institution = qualificationDTO.Institution;

                DB.SubmitChanges();
                return "success";
            }
            catch (Exception ex)
            {
                return ex.Message;
            }
        }
    }
}
